# Contributor: Kevin Daudt <kdaudt@alpinelinux.org>
# Maintainer: Kevin Daudt <kdaudt@alpinelinux.org>
pkgname=zabbix-agent2-alpine
pkgver=5.4.9
pkgrel=5
_plugins_version=0.2
pkgdesc="Zabbix Agent2 with additional plugins"
url="https://gitlab.alpinelinux.org/alpine/infra/infra-packages/-/tree/master/infra/zabbix-agent2-alpine"
arch="all !riscv64" # missing riscv64-specific functionality
license="GPL-2.0-or-later"
makedepends="go autoconf automake pcre-dev zlib-dev openssl-dev openssl-libs-static"
options="!check" # no test suite
subpackages="$pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/zabbix/zabbix/archive/$pkgver.tar.gz
	https://gitlab.alpinelinux.org/alpine/infra/zabbix-agent2-plugins/-/archive/v$_plugins_version/zabbix-agent2-plugins-v$_plugins_version.tar.gz
	zabbix-agent2.initd
	zabbix_agent2.conf
	enable-plugins.patch
	go-mod-add-dependencies.patch
	"
install="$pkgname.pre-install"
builddir="$srcdir/zabbix-$pkgver"

export GOPATH="$srcdir/go"
export GOCACHE="$srcdir/go-build"
export GOTEMPDIR="$srcdir/go"

export GOFLAGS="$GOFLAGS -modcacherw"

prepare() {
	default_prepare
	./bootstrap.sh

	cp -r "$srcdir"/zabbix-agent2-plugins-v$_plugins_version/plugins/* \
		"$builddir"/src/go/plugins/
}

build() {
	./configure \
		--sysconfdir=/etc/zabbix \
		--mandir=/usr/share/man \
		--with-openssl \
		--enable-agent2 \
		--enable-static
	make
}

package() {
	install -Dm0755 src/go/bin/zabbix_agent2 $pkgdir/usr/sbin/zabbix_agent2
	install -Dm0755 $srcdir/zabbix-agent2.initd $pkgdir/etc/init.d/zabbix-agent2
	install -dm0755 $pkgdir/etc/zabbix/agent2.conf.d/

	install -Dm0644 $srcdir/zabbix_agent2.conf $pkgdir/etc/zabbix/zabbix_agent2.conf
}

sha512sums="
446dd2803823daef00ebaaef1df53459d7ded6668908fd974d1134751b645cc14a28cdf537289a80f7faf4848e6d886043d487c77f7841bc0f64d5d134fc4f0e  zabbix-agent2-alpine-5.4.9.tar.gz
e3e1110f24f27b2d7ff314a7fdf89d3d76e690bd83a6c3c074320bb84ef1980586fb472a7e251b6dc6d07dbf4767fe381f0c3e3e24c89380f37c44a1a7e34ed9  zabbix-agent2-plugins-v0.2.tar.gz
3d30e97e23c19057d89383b11c589bc0f1e0134f4a090f17baaf04c335dffd708c533596a4ff1b06cf36a4cfb1cb549a372cdb07081b186c991395c2156aaeaa  zabbix-agent2.initd
bdef1e8ae6d993fe28d4ed493800effdc499f7a9ebc3a2f71290f752d926912bef4726f60907ba932953bcfa1622a6aae514f132c339ef2b01a0ca6791178153  zabbix_agent2.conf
fb5b237edd229c6300867084810c9bb051e9c7ee09fc4499837d8be9f99678549de757cf2c5dbecf513322e4705e7ea2be8e4f4965fded3d09a10a69ec17b37e  enable-plugins.patch
d49a2e707e09fdcbe5056f72ac3c6cff50025a4c39a539416cf99b292ad88b49426d9ee13ba93618b43d8a6a6556a5d1bd382476317d513a85f7de632755f0b9  go-mod-add-dependencies.patch
"
